package com.base.java;

import com.base.java.disruptor.DisruptorMQService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;


@SpringBootApplication
public class Application implements CommandLineRunner {

    private AtomicInteger integer = new AtomicInteger(1);

    private ExecutorService executor = Executors.newFixedThreadPool(10);

    @Autowired
    private DisruptorMQService disruptorMQService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }

    @Override
    public void run(String... args) throws Exception {
        Runnable r = () -> {
            disruptorMQService.pushMessage("index : "+ integer .getAndIncrement() + " Hello world !");
        };
        for(int i = 0; i< 1000000; i++){
            executor.submit(r);
        }
    }
}
